﻿@model Article
@{  var format = (TextFormats)ViewData["Format"]; }
<table style="width: 100%" cellpadding="0" cellspacing="5">
    <tr>
        <td style="vertical-align: top; width: 630px;">
            @Html.ValidationSummary()
            <div id="title_field">
                <h4 style="margin: 0px">
                    <label for="Title">
                        @Html.Global("RES_TITLE") @Html.ValidationMessageFor(m => m.Title, "*"):</label>
                </h4>
                @( Ajax.DnaFor().TextBox(m => m.Title)
                                .Width(630)
                                .Value(Model != null ? Model.Title : "")
                                .GetHtml()
                )
            </div>
            <div style="padding: 5px 0px;">
                <ul class="d-horizontal-list">
                    <li>
                        <h4 style="margin: 0px;">
                            @Html.Global("publishing", "ContentFormat"):</h4>
                    </li>
                    @if (format == TextFormats.WiKi)
                    {
                        <li>
                            @if ((Model != null) && (Model.ID>0))
                            { 
                                @Html.ActionLink(Html.Global("publishing", "HtmlFormat"), "Edit", new { id = Model.ID, format = (int)TextFormats.Xhtml })
                            }
                            else
                            { 
                                @Html.ActionLink(Html.Global("publishing", "HtmlFormat"), "Create", new { categoryID = Request.QueryString["categoryID"], format = (int)TextFormats.Xhtml })
                            }
                        </li>
                        <li>
                            @Ajax.Dna().Link("javascript:void(0);").ImageIcons(Url.Content("~/Content/Images/ok.gif")).LocText("publishing", "WikiFormat").GetHtml()
                            <input type="hidden" value="2" name="Article.ContentFormat" />
                        </li>
                    }
                    else
                    { 
                        <li>
                            @Ajax.Dna().Link("javascript:void(0);").ImageIcons(Url.Content("~/Content/Images/ok.gif")).LocText("publishing", "HtmlFormat").GetHtml()
                        </li>
                        <li>
                            @if (Model != null)
                            {
                                @Html.ActionLink(Html.Global("publishing", "WikiFormat"), "Edit", new { id = Model.ID, format = (int)TextFormats.WiKi })
                            }
                            else
                            { 
                                @Html.ActionLink(Html.Global("publishing", "WikiFormat"), "Create", new { categoryID = Request.QueryString["categoryID"], format = (int)TextFormats.WiKi })
                            }
                            <input type="hidden" value="1" name="Article.ContentFormat" />
                        </li>
                    }
                </ul>
            </div>
            <span style="clear: both;"></span>
            @if (format == TextFormats.WiKi)
            {
                <div>
                    @{
                Ajax.Dna().RichTextBox("Article.Body")
                    .AllowHTMLEditing(false)
                    .Options(opts => { opts.Mode = "source"; })
                    .Resizable()
                    .Height(400)
                    .Value(Model != null ? Model.Body : Html.Global("forums", "WriteYourContent"))
                    .ToolPanes(panes =>
                    {
                        panes.Clear();
                        panes.Add().CustomTools(tb =>
                        {
                            tb.Add().AddCombo(combo =>
                            {
                                combo.Items(items =>
                                {
                                    items.AddValue(Html.Global("RES_QUOTE"), "((({0})))");
                                    items.AddValue(Html.Global("RES_HEAD")+ " 1", "=={0}==");
                                    items.AddValue(Html.Global("RES_HEAD") + " 2", "==={0}===");
                                    items.AddValue(Html.Global("RES_HEAD") + " 3", "===={0}====");
                                    items.AddValue(Html.Global("RES_HEAD") + " 4", "====={0}====");
                                    items.AddValue(Html.Global("RES_HEAD") + " 5", "======{0}======");
                                })
                                .Options(opts =>
                                {
                                    opts.OnItemSelected = "$wf(ui.value);";
                                })
                                .DropDownList();

                            })
                            .AddIcon("d-rte-icon d-rte-toc", "$wf(\"{toc}\");", "")
                            .AddIcon("d-rte-icon d-rte-bold", "$wf(\"'''{0}'''\");", "")
                            .AddIcon("d-rte-icon d-rte-italic", "$wf(\"''{0}''\");", "")
                            .AddIcon("d-rte-icon d-rte-underline", "$wf('__{0}__');", "")
                            .AddIcon("d-rte-icon d-rte-strikeThrough", "$wf('--{0}--');", "")
                            .AddSeparator()
                            .AddIcon("d-rte-icon d-rte-insertOrderedList", "$wf(\"#{0}\");", "")
                            .AddIcon("d-rte-icon d-rte-insertUnorderedList", "$wf(\"*{0}\");", "")
                            .AddSeparator()
                            .AddIcon("d-rte-icon d-rte-justifyLeft", "$wf('<{0}<');", "")
                            .AddIcon("d-rte-icon d-rte-justifyRight", "$wf('>{0}>');", "")
                            .AddSeparator()
                            .AddIcon("d-rte-icon d-rte-link", "$wf('[{0}|{0}]');", "")
                            .AddIcon("d-rte-icon d-rte-superscript", "$wf('^^{0}^^');", "")
                            .AddIcon("d-rte-icon d-rte-subscript", "$wf(',,{0},,');", "")
                            .AddIcon("d-rte-icon d-rte-img", "$dna.fileDlg(\"" + Url.Action("Dialog", "WebFiles", new { Area = "", website = WebSiteContext.Current.Web.Name }) + "\",null,function(_src){$wf('[image|{0}|'+_src+']');});", "")
                            .AddIcon("d-rte-icon d-rte-insertHorizontalRule", "$wf(\"----\");", "")
                            .AddIcon("d-rte-icon d-rte-insertCode", "$wf('<code html>{0}</code>');", "");
                        });
                    })
                    .Render();
                    }
                </div>
            }
            else
            { 
                <div>
                    @{Ajax.Dna().RichTextBox("Article.Body")
                          .ToolPanes(panes =>
                          {
                              panes.Add().CustomTools(tool =>
                              {
                                  tool.Add().Buttons(buttons =>
                                  {
                                      buttons.AddIconButton("d-rte-icon d-rte-link", "$(\"#insertDlg\").dialog(\"open\");");
                                      buttons.AddIconButton("d-rte-icon d-rte-img", "$dna.fileDlg(\"" + Url.Action("Dialog", "WebFiles", new { Area = "", website = WebSiteContext.Current.Web.Name }) + "\",null,function(_src){ $(\"#Article_Body\").richtextbox(\"runCmd\",\"insertHTML\",\"<img src='\"+_src+\"' alt=''/>\");});");
                                      Ajax.Dna().Dialog(Html.Global("RES_INSERT_LINK"))
                                          .Name("insertDlg")
                                          .HtmlAttributes(new { style = "overflow:visible" })
                                          .Options(opts =>
                                          {
                                              opts.AutoOpen = false;
                                              opts.ShowModal = true;
                                              opts.IsResizable = false;
                                              opts.Position = new string[] { "center", "center" };
                                          })
                                          .Body(@<text>
                        <table>
                            <tr>
                                <td>@Html.Global("publishing", "Url")
                                </td>
                                <td>@Ajax.Dna().TextBox("linkUrl").Value("http://").GetHtml()
                                </td>
                            </tr>
                            <tr>
                                <td>@Html.Global("RES_TEXT")
                                </td>
                                <td>@Ajax.Dna().TextBox("linkText").GetHtml()
                                </td>
                            </tr>
                            <tr>
                                <td>@Html.Global("RES_TOOLTIP")
                                </td>
                                <td>@Ajax.Dna().TextBox("linkTitle").GetHtml()
                                </td>
                            </tr>
                            <tr>
                                <td>@Html.Global("RES_TARGET")
                                </td>
                                <td>@(Ajax.Dna().ComboBox("linkTargets")
            .DropDownStyle(DropdownStyles.DropdownList)
            .Select("_self")
            .Bind(new string[] { "_self", "_blank", "_parent", "_top" })
            .GetHtml())
                                </td>
                            </tr>
                        </table>
                        </text>)
                                 .Buttons(btns =>
                                 {
                                     btns.Add(Html.Global("RES_INSERT"), "$(this).dialog('close'); $(\"#Article_Body\").richtextbox(\"runCmd\",\"insertHTML\",\"<a src='\"+$('#linkUrl').val()+\"' target='' title='\"+$('#linkTitle').val()+\"' />\"+$('#linkText').val()+\"</a>\");");
                                     btns.AddClose().Text = Html.Global("RES_CLOSE");
                                 })
                                 .Render();
                                  });
                              });
                          })
                          .Height(400).Resizable()
                          .Value((Model != null) ? Model.Body : "")
                          .Render();}
                </div>
            }
            @{ Ajax.Dna().CollapsablePanel()
                    .Title(Html.Global("publishing", "Properties"))
                     .ImageUrl(Url.Content("~/content/images/icon_process_16.png"))
                    .Expand(false)
                    .HtmlAttributes(new { style = "margin-top:5px;" })
                    .Body(@<text>
                <div id="summary_field">
                    <h4 style="margin: 0px;">
                        <label for="Summary">
                            @Html.Global("RES_SUMMARY") :</label></h4>
                    @Ajax.DnaFor().TextArea(m => m.Summary).Width(600).Height(50).Resizable().GetHtml()
                </div>
                <div id="tags_field">
                    <h4 style="margin: 0px;">
                        <label for="Tags">
                            @Html.Global("Publishing", "Tags") :</label></h4>
                    @Ajax.DnaFor().TextBox(m => m.Tags).Width(600).GetHtml()
                    <div>
                        (@Html.Global("publishing", "SeparateTags"))</div>
                    <div>
                        @Html.Global("publishing", "Tags_Tips")
                    </div>
                </div>
                <div>
                    <h4 style="margin: 0px">
                        <label for="ImageUrl">
                            @Html.Global("RES_IMAGEURL"):</label></h4>
                    @Ajax.DnaFor().TextBox(m => m.ImageUrl).Width(600).GetHtml()
                </div>
                </text>)
            .Render();
               Ajax.Dna().CollapsablePanel()
                       .ImageUrl(Url.Content("~/content/images/icon_link_16.png"))
                      .Expand(false)
                       .Title(Html.Global("publishing", "SendTrackbackto"))
                       .HtmlAttributes(new { style = "margin-top:5px;" })
                       .Body(@<text>
                @Ajax.DnaFor().TextBox(m => m.SendTrackbackUrls).Width(600).GetHtml()
                <div>
                    (
                    @Html.Global("publishing", "SeparateUrls") )</div>
                <p>
                    @Html.Global("publishing", "Trackback_Tips")
                </p>
                </text>)
                       .Render();
            }
        </td>
        <td style="padding-top: 0px; vertical-align: top; width: 270px;">
            @if ((Model != null) && (Model.ID > 0))
            {
                Ajax.Dna().CollapsablePanel()
                     .ImageUrl(Url.Content("~/content/images/icon_earth_16.gif"))
          .Title(Html.Global("publishing", "Globalization"))
          .Body(@<text>
                <div>
                    @Html.Global("Publishing", "CurrentLanguage") : @Html.CurrentCultureInfo().DisplayName</div>
                <div style="overflow: auto;">
                    <span style="float: left;">
                        @Html.Global("RES_TRANSLATE_TO"):</span>
                    @{ var builder = new NodeUIBuilder();
                       builder.WriteBeginTag("ul", new { Class = "ui-helper-reset", style = "float:left;" });
                       foreach (var language in WebSiteContext.Current.Languages)
                       {
                           if (language.Value.ToString() == Model.Language) { continue; }
                           builder.WriteBeginTag("li", new { Class = "ui-helper-reset", style = "float:left;margin-left:2px;" })
                           .WriteBeginTag("a", new
                           {
                               href = Url.Action("Translate", "Article", new { id = Model.ID, lang = language.Value }),
                               title = language.Title
                           })
                           .WriteImage(language)
                           .WriteEndTag("a")
                           .WriteEndTag("li");
                       }
                       builder.WriteEndTag("ul");
                    }
                    @MvcHtmlString.Create(builder.ToString())
                </div>
                </text>)
          .Render();
            }
            @{     Ajax.Dna().CollapsablePanel()
                    .Title(Html.Global("RES_CATEGORY"))
                     .HtmlAttributes(new { style = "margin-top:5px;" })
                    .ImageUrl(Url.Content("~/content/images/icon_cat_16.gif"))
                    .Body(@<text>
                <input type="hidden" name="Article.CategoryID" id="CategoryID" value="@(Model != null ? Model.CategoryID : ViewBag.DefaultCategoryID)" />
                <input type="hidden" name="Article.Categories" id="Categories" value="@(Model != null ? Model.Categories : "")" />
                @{
                    Ajax.Dna().TreeView("Category_TreeView")
                        .ExpandedLevel(1)
                        .SinglePathExpand(true)
                        .HtmlAttributes(new { style = "height:200px;border:1px solid #cccccc;overflow:auto;padding-top:10px;" })
                          .Options(opts =>
                        {
                            opts.OnNodeSelected = "$(\"#CategoryID\").val($(node).attr(\"key\")); $(\"#lbCategory\").text($(node).children(\".d-treenode-content\").find(\".d-treenode-text\").text());";
                            opts.OnNodeChecked = "_getCheckedNodeValues();";
                        })
                        .Bind(((HierarchicalNodeProviderBase)ViewBag.Provider).RootNode, (node) =>
                        {
                            var cat = node.Item as Category;
                            if (cat.IsRoot)
                                node.Title = Html.Global("publishing", "Uncategoried");
                            return true;
                        }, true)
                        .ShowCheckboxs(true)
                        .Render();
                }
                <table id="addCategoryPane">
                    <tr>
                        <td style="white-space: nowrap;">
                            @Html.Global("publishing", "PrimaryCategory"):
                        </td>
                        <td colspan="2">
                            <label id="lbCategory">
                                @Html.Global("publishing", "Uncategoried")
                            </label>
                        </td>
                    </tr>
                    <tr>
                        <td style="white-space: nowrap;">
                            @Html.Global("publishing", "SelectedCategories"):
                        </td>
                        <td colspan="2">
                            <label id="lbCategories">
                            </label>
                        </td>
                    </tr>
                    <tr>
                        <td colspan="3">
                            @Html.Global("publishing", "AddCategory"):
                        </td>
                    </tr>
                    <tr>
                        <td colspan="2">
                            @Ajax.Dna().TextBox("NewCategoryTitle").Width(120).Value("").GetHtml()
                        </td>
                        <td>
                            @Ajax.Dna().Button().LocText("RES_ADD").Click(Ajax.GeneratejQueryAjaxScripts(new jQueryAjaxOptions()
                                        {
                                            HttpMethod = "POST",
                                            Url = Url.Action("Add", "Category"),
                                            OnBeforeSend = "if ($('#NewCategoryTitle').val()=='') {alert('" + Html.Global("publishing","CategoryNameRequried") + "'); $('#NewCategoryTitle').focus();return false;} ",
                                            Data = "{id:$('#CategoryID').val(),title:$('#NewCategoryTitle').val()}",
                                            OnSuccess = "_addCategoryTreeNode(data);",
                                        })).GetHtml()
                        </td>
                    </tr>
                </table>
                </text>)
                    .Render();


                   Ajax.Dna().CollapsablePanel()
                        .HtmlAttributes(new { style = "margin-top:5px;" })
                        .ImageUrl(Url.Content("~/content/images/icon_comments_16.png"))
                       .Title(Html.Global("publishing", "Discussion"))
                       .Body(@<text>
                <div style="margin-left: 5px; overflow: auto;">
                    <div style="clear: both;">
                        @Ajax.Dna().Checkbox("Article.AllowComments", Html.Global("publishing", "AllowComments"), Model != null ? Model.AllowComments : true,
                         Url.Content("~/content/images/icon_accept_16.png"),
                           Url.Content("~/content/images/icon_block_16.png")).GetHtml()
                    </div>
                    <div style="clear: both;">
                        @Ajax.Dna().Checkbox("Article.AllowPingback", Html.Global("publishing", "AllowPings"), Model != null ? Model.AllowPingback : true,
                         Url.Content("~/content/images/icon_accept_16.png"),
                               Url.Content("~/content/images/icon_block_16.png")).GetHtml()
                    </div>
                </div>
                </text>)
                       .Render();

                   Ajax.Dna().CollapsablePanel()
                        .HtmlAttributes(new { style = "margin-top:5px;" })
                       .Title(Html.Global("publishing", "Visibility"))
                       .Body(@<text>
                <table>
                    <tr>
                        <td align="right">
                            @Html.Global("publishing", "Visibility"):
                        </td>
                        <td>
                            @Ajax.Dna().Checkbox("Article.IsPrivate", Html.Global("publishing", "IsPrivate"), Model != null ? Model.IsPrivate : false,
                             Url.Content("~/content/images/icon_accept_16.png"),
                                   Url.Content("~/content/images/icon_block_16.png")).GetHtml()
                        </td>
                    </tr>
                    <tr>
                        <td align="right">
                            <label for="Password">@Html.Global("RES_PASSWORD"):</label>
                        </td>
                        <td>
                            @Ajax.DnaFor().TextBox(m => m.Password).Password().Width(155).GetHtml()
                        </td>
                    </tr>
                    <tr>
                        <td>
                            @Ajax.Dna().Checkbox("Article.IsPublished", Html.Global("publishing", "PublishImmediately") + ":", Model != null ? Model.IsPublished : true,
                     Url.Content("~/content/images/icon_accept_16.png"), Url.Content("~/content/images/icon_block_16.png")).GetHtml()
                        </td>
                        <td>
                            @Ajax.Dna().DatePicker("Article.Posted").Options(opts =>
                           {
                               opts.Value = Model != null ? Model.Posted : DateTime.Now;
                               opts.ShowButtonPanel = true;
                               opts.DateFormatString = "MM/dd/yyyy";
                               opts.LocID = System.Threading.Thread.CurrentThread.CurrentUICulture.Name;
                               opts.AllowChangeMonth = true;
                               opts.AllowChangeYear = true;
                           }).GetHtml()
                        </td>
                    </tr>
                </table>
                </text>)
                               .Render();
            }
        </td>
    </tr>
    <tr>
        <td colspan="2">
            <div style="padding: 10px; text-align: center;">
                @Ajax.Dna().Button("btnSubmit").Submit().LocText("publishing", "Post").ImageIcons(Url.Content("~/content/images/icon_save.gif")).GetHtml()
                @if ((Model != null) && (Model.ID > 0))
                {
                    @Ajax.ActionButton(Html.Global("RES_DELETE"), "ui-icon ui-icon-close",
                       "Delete", "Article", new jQueryAjaxOptions()
                       {
                           AutoBlocking = true,
                           Confirm = Html.Global("publishing", "DeleteArticleQuestion"),
                           HttpMethod = "POST",
                           OnSuccess = "location=\"" + (new CategoryWrapper(Model.Category)).PermaLink + "\";",
                       }, new { id = Model.ID })

                    @Ajax.Dna().Button("btnCancel").LocText("RES_CANCEL").Click("location=\"" + Url.Action("Details", new { id = Model.ID }) + "\";").ImageIcons(Url.Content("~/content/images/icon_back_16.png")).GetHtml()
                }
            </div>
        </td>
    </tr>
</table>
<script type="text/javascript">
    function $wf(_format) {
        $dna.insertFormat($("#Article_Body"), _format);
    }

    function _getCheckedNodeValues() {
        var nodes = $('#Category_TreeView').dtree("getCheckedNodes");
        var keys = [], labels = [];
        $.each(nodes, function (i, n) {
            keys.push($(n).attr("key"));
            labels.push($(n).children(".d-treenode-content").find(".d-treenode-text").text());
        });
        $("#Categories").val(keys.join(","));
        $("#lbCategories").text(labels.join(","));
    }

    function _initWriter(isEditMode) {
        if (isEditMode) {
            $('#Category_TreeView').dtree("select", $('#Category_TreeView').dtree("findNodeElementByKey", $("#CategoryID").val()));
            _setCheckedNodeValues();
        }
        else {
            $('#Category_TreeView').dtree("select", $('#Category_TreeView').children(".d-treenode").first());
        }
    }

    function _addCategoryTreeNode(data) {
        var n = $("<li key=\"" + data + "\"><span class=\"d-treenode-text\">" + $("#NewCategoryTitle").val() + "</span></li>");
        $('#Category_TreeView').dtree("addNode", n);
        $('#NewCategoryTitle').val('');
    }

    function _setCheckedNodeValues() {
        var valArgs = $("#Categories").val();
        if (valArgs) {
            var vals = valArgs.split(",");
            var txts = new Array();
            $.each(vals, function (i, n) {
                var $node = $('#Category_TreeView').dtree("findNodeElementByKey", "key");
                if ($node.length) {
                    $node.children(".d-treenode-content").find(".d-treenode-checkbox").attr("checked", true);
                    txts.push($node.children(".d-treenode-content").find(".d-treenode-text").text());
                    //alert($node.children(".d-treenode-content").find(".d-treenode-text").text());
                }
            });
            //alert(txts.join(","));
            $("#lbCategories").text(txts.join(","));
        }
    }
</script>
@{ Html.RegisterStartupScript(Model != null ? "_initWriter(true);" : "_initWriter(false);"); }
@Html.StartupScripts()
